from flask import Flask
from flask_cors import CORS

from api.buys import buy_bp
from api.users import user_bp
from api.books import book_bp
from api.libraries import library_bp
from api.informations import information_bp
from api.borrow import borrow_bp
from api.comments import comment_bp
from config import DatabaseConfig
from models import db

app = Flask(__name__)

app.register_blueprint(user_bp, url_prefix='/users')
app.register_blueprint(book_bp, url_prefix='/books')
app.register_blueprint(library_bp, url_prefix='/libraries')
app.register_blueprint(borrow_bp, url_prefix='/borrows')
app.register_blueprint(information_bp, url_prefix='/information')
app.register_blueprint(comment_bp, url_prefix='/comments')
app.register_blueprint(buy_bp, url_prefix='/buys')


#  数据库连接配置
app.config.from_object(DatabaseConfig)
db.init_app(app)
CORS(app)

@app.route('/')
def hello_world():  # put application's code here e
    return 'ddd'



if __name__ == '__main__':
    app.run()
    with app.app_context():
        db.create_all()
